package com.xingkeduo.pojo.json;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.dto.Shops.ShopsDTO;
import com.xingkeduo.pojo.dto.Shops.ShopsServprodDTO;
import com.xingkeduo.pojo.dto.Shops.shopsApi.ShopsGrainApiDTO;
import com.xingkeduo.pojo.enums.CommentStar;
import com.xingkeduo.pojo.enums.ShopsStatus;
import com.xingkeduo.pojo.enums.ShopsTerminal;
import com.xingkeduo.pojo.query.ShopsQuery;
import com.xingkeduo.pojo.table.CitiesTable;
import com.xingkeduo.pojo.table.ShopsTable;
import com.xingkeduo.pojo.vo.ActivityVo;
import com.xingkeduo.pojo.vo.ServprodVo;
import com.xingkeduo.pojo.vo.ShopsTableVo;
import com.xingkeduo.tool.DateTimeUtils;
import com.xingkeduo.tool.LocationUtils;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.InputParamException;
import com.xingkeduo.util.tool.CommonUtil;

public class ShopsJson extends BaseJson {


    public static ObjectNode toJsonForShopsList(Map<String,Object> result) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();

//        root.put("upgrade_system", Boolean.valueOf(result.get("upgrade_system")==null? "true":result.get("upgrade_system").toString()));//383是false
        
        root.put("has_join_banner", false);
        //店铺列表
        Map<Long,List<ActivityVo>> shopActivityMap = (Map<Long, List<ActivityVo>>) result.get("shopActivityTag");//店铺活动标签
        ArrayNode storeListArray = MAPPER.createArrayNode();
        List<ShopsTableVo> storeList = (List<ShopsTableVo>) result.get("store_list");
        if(storeList!=null && storeList.size()>0) {
            for (int i = 0; i < storeList.size(); i++) {
                storeListArray.add(ShopsJson.toJsonForShops(storeList.get(i),shopActivityMap));
            }
        }
        root.put("store_list", storeListArray);

        //最近服务店铺
        //ArrayNode nearshopArray = MAPPER.createArrayNode();
        ObjectNode nearShops = MAPPER.createObjectNode();
        ShopsTableVo nearVo = (ShopsTableVo) result.get("last_service_store_record");
        if(nearVo!=null) {
            nearShops = toJsonForShops(nearVo,shopActivityMap);
            //nearshopArray.add(nearShops);
            root.put("last_service_store_record", nearShops);
        }else {
            //ArrayNode cityArray = MAPPER.createArrayNode();
//            root.put("last_service_store_record", nearShops);
        	root.put("last_service_store_record", false);
        }


        //banner
        ArrayNode bannerArray = MAPPER.createArrayNode();
        root.put("banner_urls", bannerArray);

        //城市列表
        Map<Long,String> cityMap = new HashMap<Long,String>();
        ArrayNode cityArray = MAPPER.createArrayNode();
        List<CitiesTable> cList = (List<CitiesTable>) result.get("city");
        if(cList!=null && cList.size()>0) {
            for (int i = 0; i < cList.size(); i++) {
                cityMap.put(cList.get(i).getId(), cList.get(i).getName());
                cityArray.add(toJsonForCity(cList.get(i)));
            }
        }
        root.put("city", cityArray);

        root.put("province_id", result.get("province_id")==null? "0":result.get("province_id").toString());
        root.put("limit", result.get("limit").toString());

        root.put("upgrade_system",false);//默认升级  切全国由true改fasle
        root.put("has_c_la_c_banner", true);//切全国由false改为true
        root.put("has_xkd_mall_banner", true);
        root.put("has_nanjing_banner", true);
        root.put("has_chongqing_activity_banner", false);
        root.put("has_nanjing_activity_banner", false);
        root.put("has_barber_banner", false);
        root.put("has_hair_plant_banner", false);
        
        if(result.get("status")!=null) {
            root.put("status", result.get("status").toString());
            root.put("select_city",cityMap.get(Long.valueOf(result.get("status").toString())));
//          if("383".equals(result.get("status").toString())) {
//        		root.put("upgrade_system",false);
//          } 
            if("52".equals(result.get("status").toString())) {
            	root.put("has_hair_plant_banner", true);
            }
            if("52".equals(result.get("status").toString()) || "321".equals(result.get("status").toString())) {
            	root.put("has_barber_banner", true);
            }
        }
        return root;
    }


    public static ObjectNode toJsonForShopDetail(Map<String,Object> result) {
        ObjectNode root = MAPPER.createObjectNode();

        ShopsTableVo vo = (ShopsTableVo) result.get("datailVo");

        root.put("store_id", vo.getId());
        root.put("latitude", vo.getLatitude());
        root.put("longitude", vo.getLongitude());
        root.put("starttime", vo.getStartTime());//门店开始营业时间
        root.put("endtime", vo.getEndTime());//门店营业结束时间
        root.put("address", vo.getAddress());
        if(vo.getDistance()!=null) {
            if(BigDecimal.valueOf(vo.getDistance()).compareTo(BigDecimal.valueOf(1000))<0) {//小于1km 处理成m
                root.put("distance", BigDecimal.valueOf(vo.getDistance()).setScale(0, RoundingMode.DOWN)+"M"); //
            }else {
                root.put("distance", LocationUtils.formartDistanceFromToKm(vo.getDistance())+"KM"); //
            }
        }else {
            root.put("distance","");
        }

        //店铺标签
        ArrayNode shopTagArray = MAPPER.createArrayNode();
        try {
            if(StringUtils.isNotEmpty(vo.getShoptag())) {
                List<String> sList =  JSONArray.parseArray(vo.getShoptag(), String.class);
                if(sList!=null) {
                    for (int i = 0; i < sList.size(); i++) {
                        if(StringUtils.isNotEmpty(sList.get(i))) {
                            shopTagArray.add(sList.get(i));
                        }
                    }
                }
            }
        }catch (Exception e) {
        }
        root.put("shopTag", shopTagArray);

        //店铺活动标签
        ArrayNode shopActivityTagArray = MAPPER.createArrayNode();
        List<ActivityVo> activityList = vo.getStoreActivityTag();
        if(activityList!=null && activityList.size()>0) {
            for (int i = 0; i < activityList.size(); i++) {
                ObjectNode aa = MAPPER.createObjectNode();
                aa.put("type", activityList.get(i).getType());
                aa.put("typeName", activityList.get(i).getTypeName());
                aa.put("shortDesc", activityList.get(i).getShotDesc());
                aa.put("longDesc", activityList.get(i).getLongDesc());
                shopActivityTagArray.add(aa);
            }
        }
        root.put("shopActivityTag", shopActivityTagArray);


        //服务及对应价格
        ArrayNode skuListArray = MAPPER.createArrayNode();
        List<ServprodVo> skuList = vo.getShopServprodList();
        if(skuList!=null && skuList.size()>0) {
            for (int i = 0; i < skuList.size(); i++) {
                skuListArray.add(toJsonOfServprodVo(skuList.get(i)));
            }
        }
        root.put("sku_list", skuListArray);

        root.put("has_bang",false);
        root.put("has_barber",false);
        root.put("has_fast",false);
        Map<Long,BigDecimal> serviceShopPrice = (Map<Long, BigDecimal>) result.get("serviceShopPrice");
        if(serviceShopPrice!=null) {
            if(serviceShopPrice.get(1L)!=null) {//单人剪发
                ArrayNode allPriceArray = MAPPER.createArrayNode();
                allPriceArray.add(String.valueOf(serviceShopPrice.get(1L).divideAndRemainder(BigDecimal.valueOf(100L))[0].intValue()));
                String s = String.valueOf(serviceShopPrice.get(1L).divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue());
                if(StringUtils.isNotEmpty(s)) {
                    if(s.length() == 1 && !"0".equals(s)) { //长度为1且不等于0时 前边+0
                        s = "0"+s;
                    }else if(s.length() == 2 && "0".equals(s.substring(s.length()-1))) {
                        s = s.substring(0, s.length()-1);
                    }
                }
                allPriceArray.add(s);
                root.put("all_price", allPriceArray);
            }
            if(serviceShopPrice.get(2L)!=null) {//单人刘海
                root.put("has_bang",true);
                ArrayNode bangArray = MAPPER.createArrayNode();
                bangArray.add(String.valueOf(serviceShopPrice.get(2L).divideAndRemainder(BigDecimal.valueOf(100L))[0].intValue()));
                String s = String.valueOf(serviceShopPrice.get(2L).divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue());
                if(StringUtils.isNotEmpty(s)) {
                    if(s.length() == 1 && !"0".equals(s)) { //长度为1且不等于0时 前边+0
                        s = "0"+s;
                    }else if(s.length() == 2 && "0".equals(s.substring(s.length()-1))) {
                        s = s.substring(0, s.length()-1);
                    }
                }
                bangArray.add(s);
                root.put("bangs_all_price", bangArray);
            }
            if(serviceShopPrice.get(4L)!=null) {//美式barber
                root.put("has_barber",true);
                ArrayNode barberArray = MAPPER.createArrayNode();
                barberArray.add(String.valueOf(serviceShopPrice.get(4L).divideAndRemainder(BigDecimal.valueOf(100L))[0].intValue()));
                String s = String.valueOf(serviceShopPrice.get(4L).divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue());
                if(StringUtils.isNotEmpty(s)) {
                    if(s.length() == 1 && !"0".equals(s)) { //长度为1且不等于0时 前边+0
                        s = "0"+s;
                    }else if(s.length() == 2 && "0".equals(s.substring(s.length()-1))) {
                        s = s.substring(0, s.length()-1);
                    }
                }
                barberArray.add(s);
                root.put("barber_all_price", barberArray);
            }
            if(serviceShopPrice.get(5L)!=null) {//十分钟快剪
                root.put("has_fast",true);
                ArrayNode fastArray = MAPPER.createArrayNode();
                fastArray.add(String.valueOf(serviceShopPrice.get(5L).divideAndRemainder(BigDecimal.valueOf(100L))[0].intValue()));
                String s = String.valueOf(serviceShopPrice.get(5L).divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue());
                if(StringUtils.isNotEmpty(s)) {
                    if(s.length() == 1 && !"0".equals(s)) { //长度为1且不等于0时 前边+0
                        s = "0"+s;
                    }else if(s.length() == 2 && "0".equals(s.substring(s.length()-1))) {
                        s = s.substring(0, s.length()-1);
                    }
                }
                fastArray.add(String.valueOf(serviceShopPrice.get(5L).divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue()));
                root.put("fast_all_price", fastArray);
            }
        }

        root.put("activity_content","");//活动名称全部置空，以活动标签的形式展示了
        root.put("bangs_activity_content","");
        root.put("barber_activity_content","");
        root.put("fast_activity_content","");

        root.put("status", ShopsStatus.get(vo.getStatus())==null? "0":ShopsStatus.get(vo.getStatus()).getOldValue());
        root.put("is_sell_service", ShopsStatus.get(vo.getStatus())==null? "0":(ShopsStatus.INIT.equals(ShopsStatus.get(vo.getStatus()))? "1":"0"));
        root.put("order_no", result.get("order_no").toString());
        root.put("is_last_service", Boolean.valueOf(result.get("is_last_service").toString()));
        root.put("is_sell_product", false);
        root.put("new_thumbnail", "http://mcdn.xingkeduo.com/image/bos/store/store_img.png");
        if(vo.getTerminal()!=null && ShopsTerminal.Box.getValue()==vo.getTerminal()) {
        	root.put("new_thumbnail", "http://mcdn.xingkeduo.com/image/bos/store/box_store_detail_img.png");
        }//else -- 普通店和box店如果是临时闭店或者 试运营状态时 展示的图片一样
        if(ShopsStatus.HOT.equals(ShopsStatus.get(vo.getStatus()))) {//状态是1
            root.put("new_thumbnail", "http://mcdn.xingkeduo.com/image/bos/store/coming_soon.png");
        }else if(ShopsStatus.TEMPCLS.equals(ShopsStatus.get(vo.getStatus()))) {
            root.put("new_thumbnail", "http://mcdn.xingkeduo.com/image/bos/store/reform_coming_soon.png");
        }

        root.put("store_name", vo.getName());
        root.put("work_week", vo.getWeekDays());

        //评论信息
        //好评数
        root.put("count", result.get("count")==null? 0:Integer.valueOf(result.get("count").toString()));

        //评论信息默认值
        root.put("user_name","");
        root.put("f_avatar","");
        root.put("comment_time", "");
        root.put("comment","");
        ArrayNode picUrlArray1 = MAPPER.createArrayNode();
        root.put("pic_url", picUrlArray1);
        root.put("star",5);
        root.put("service_type","");
        root.put("service_admin", "");//发型师昵称 
        if(result!=null && result.get("comment")!=null) {
            //用户昵称
            root.put("user_name", result.get("user_name")==null? "":result.get("user_name").toString());
            //用户头像
            root.put("f_avatar", result.get("f_avatar")==null? "":result.get("f_avatar").toString());

            Map commentMap = (Map) result.get("comment");
            //发型师昵称
            root.put("service_admin", commentMap.get("adminName")==null?  "":commentMap.get("adminName").toString());
            
            //评论时间
            String createTime = commentMap.get("createdTime")==null? "":commentMap.get("createdTime").toString();
            if(StringUtils.isNotEmpty(createTime)) {
                root.put("comment_time", createTime.replace('-', '/'));
            }else {
                root.put("comment_time", "");
            }
            //评论内容
            root.put("comment", commentMap.get("comment")==null?  "":commentMap.get("comment").toString());

            //评价图片
            ArrayNode picUrlArray = MAPPER.createArrayNode();
            String pic = commentMap.get("picIds")==null? "":commentMap.get("picIds").toString();
            if(StringUtils.isNotEmpty(pic)) {
                String[] ss = pic.split(",");
                if(ss!=null && ss.length>0) {
                    for (int j = 0; j < ss.length; j++) {
                        if(StringUtils.isNotEmpty(ss[j])) {
                            picUrlArray.add(ss[j]);
                        }
                    }
                }
            }
            root.put("pic_url", picUrlArray);

            //评价星级
            String commentStarName = (String) commentMap.get("commentStar");
            if(StringUtils.isNotEmpty(commentStarName)) {
                root.put("star", CommentStar.getKeyByName(commentStarName));
            }
            //评价对应的服务类型
            String serviceTypeName = (String) commentMap.get("serviceTypeName");
            if(StringUtils.isNotEmpty(serviceTypeName)) {
                root.put("service_type", serviceTypeName);
            }
        }else {
        	root.put("count",0);
        }

        root.put("has_c_la_c_banner", false);
        root.put("has_barber_banner", false);
        root.put("has_hair_plant_banner", false);
        root.put("has_barber_banner_50", false);
        root.put("has_barber_banner_69", false);
        String shopids1 = ",70,57,45,107,58,";////植发问卷调查banner
        String shopids2 = ",31,35,181,86,44,30,79,68,63,56,77,181,117,65,48,";//5折barber券
        String shopids3 = ",62,74,";//6.9折barber券
        String notInShopIds = ",45,57,58,49,98,56,75,74,88,89,171,172,166,119,169,167,";
        if(shopids1.contains("," + vo.getId() +",")) {
        	root.put("has_hair_plant_banner", true);
        }else if(shopids2.contains("," + vo.getId() +",")) {
        	root.put("has_barber_banner_50", true);
        }else if(shopids3.contains("," + vo.getId() +",")) {
        	root.put("has_barber_banner_69", true);
        }else if(!notInShopIds.contains("," + vo.getId() +",")) {
        	root.put("has_c_la_c_banner", true);
        }
        
        return root;
    }

    public static ObjectNode toJsonForCity(CitiesTable citiesTable) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("f_id", citiesTable.getId());
        root.put("f_name", citiesTable.getName());
        return root;
    }

    public static ObjectNode toJsonOfServprodVo(ServprodVo servprodVo) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("service_type", servprodVo.getServiceId());
        root.put("name", servprodVo.getName());
        root.put("description", servprodVo.getDesc());
        root.put("activity_content", servprodVo.getActivityContent());
        root.put("is_new", servprodVo.isNew());

        ArrayNode priceArray = MAPPER.createArrayNode();
        if(servprodVo.getPrice()!=null) {
            priceArray.add(String.valueOf(servprodVo.getPrice().divideAndRemainder(BigDecimal.valueOf(100L))[0].intValue()));
            String s = String.valueOf(servprodVo.getPrice().divideAndRemainder(BigDecimal.valueOf(100L))[1].intValue());
            if(StringUtils.isNotEmpty(s)) {
                if(s.length() == 1 && !"0".equals(s)) { //长度为1且不等于0时 前边+0
                    s = "0"+s;
                }else if(s.length() == 2 && "0".equals(s.substring(s.length()-1))) {
                    s = s.substring(0, s.length()-1);
                }
            }
            priceArray.add(s);
        }
        root.put("all_price", priceArray);
        return root;
    }

    public static ObjectNode toJsonForShops(ShopsTableVo vo, Map<Long,List<ActivityVo>> shopActivityMap) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("id", vo.getId());
        root.put("city_id", vo.getCitiesId()==null? "0":vo.getCitiesId().toString());
        root.put("status", ShopsStatus.get(vo.getStatus())==null? "0":ShopsStatus.get(vo.getStatus()).getOldValue());
        root.put("area_name", StringUtils.isNotEmpty(vo.getAreaName())? vo.getAreaName():"");//
        root.put("market_address", vo.getShortaddr());
        //店铺标签
        ArrayNode shopTagArray = MAPPER.createArrayNode();
        try {
            if(StringUtils.isNotEmpty(vo.getShoptag())) {
                List<String> sList =  JSONArray.parseArray(vo.getShoptag(), String.class);
                if(sList!=null) {
                    for (int i = 0; i < sList.size(); i++) {
                        if(StringUtils.isNotEmpty(sList.get(i))) {
                            shopTagArray.add(sList.get(i));
                        }
                    }
                }
            }
        }catch (Exception e) {
        }
        root.put("shopTag", shopTagArray);

        //店铺活动标签
        ArrayNode shopActivityTagArray = MAPPER.createArrayNode();
        if(shopActivityMap!=null && shopActivityMap.get(vo.getId())!=null && shopActivityMap.get(vo.getId()).size()>0) {
            for (int i = 0; i < shopActivityMap.get(vo.getId()).size(); i++) {
                ObjectNode aa = MAPPER.createObjectNode();
                aa.put("type", shopActivityMap.get(vo.getId()).get(i).getType());
                aa.put("typeName", shopActivityMap.get(vo.getId()).get(i).getTypeName());
                aa.put("shortDesc", shopActivityMap.get(vo.getId()).get(i).getShotDesc());
                aa.put("longDesc", shopActivityMap.get(vo.getId()).get(i).getLongDesc());
                shopActivityTagArray.add(aa);
            }
        }
        root.put("shopActivityTag", shopActivityTagArray);

        if(vo.getDistance()!=null) {
            if(BigDecimal.valueOf(vo.getDistance()).compareTo(BigDecimal.valueOf(1000))<0) {//小于1km 处理成m
                root.put("distance", BigDecimal.valueOf(vo.getDistance()).setScale(0, RoundingMode.DOWN)+"M"); //
            }else {
                root.put("distance", LocationUtils.formartDistanceFromToKm(vo.getDistance())+"KM"); //
            }
        }else {
            root.put("distance","");
        }

        root.put("currenttime", new Date().getTime()/1000);//
        if(StringUtils.isNotEmpty(vo.getStartTime())) {
            Date d = new Date();
            try {
                d = DateTimeUtils.yyyy_MM_dd_HH_mmToDate(vo.getStartTime());
            } catch (ParseException e) {
            }
            root.put("starttime", d.getTime()/1000);//
        }
        if(StringUtils.isNotEmpty(vo.getEndTime())) {
            Date d = new Date();
            try {
                d = DateTimeUtils.yyyy_MM_dd_HH_mmToDate(vo.getEndTime());
            } catch (ParseException e) {
            }
            root.put("endTime", d.getTime()/1000);//
        }

        root.put("is_sell_product", "0");
        root.put("has_barber", false);
        root.put("thumbnail_url", "http://mcdn.xingkeduo.com/image/bos/store/store_img.png");
        if(vo.getTerminal()!=null && ShopsTerminal.Box.getValue()==vo.getTerminal()) {//box店时
        	root.put("thumbnail_url", "http://mcdn.xingkeduo.com/image/bos/store/box_store_img.png");
        }//else -- 普通店和box店如果是临时闭店或者 试运营状态时 展示的图片一样
        if(ShopsStatus.HOT.equals(ShopsStatus.get(vo.getStatus()))) {//状态是1 对应老系统1
            root.put("thumbnail_url", "http://mcdn.xingkeduo.com/image/bos/store/coming_soon.png");
        }else if(ShopsStatus.TEMPCLS.equals(ShopsStatus.get(vo.getStatus()))) {//状态是3 -- 对应老系统2
            root.put("thumbnail_url", "http://mcdn.xingkeduo.com/image/bos/store/reform_coming_soon.png");
        }
        root.put("name", vo.getName());
        return root;
    }


    public static ShopsQuery createQueryForShops(String json) throws Throwable {
        ShopsQuery query = new ShopsQuery();
        JsonNode root = validJson(json);
        if (root == null)
            return query;
        query.setId(validId(root, YesNoEnum.YES));
        return query;
    }

    public static ShopsDTO createTableForModifyShops(String urlParam, ShopsDTO shopsDTO) throws Throwable {
        JsonNode root = validJson(urlParam);
        if (root == null)
            throw new InputParamException(InputParamException.Type.INVALID, "参数");
        shopsDTO.setId(validId(root, YesNoEnum.YES));
        return shopsDTO;
    }

    public static ObjectNode toJson(ShopsDTO shopsDTO) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();

        if (shopsDTO != null)
        {
            root.put("id", shopsDTO.getId());
            root.put("code", shopsDTO.getCode());
            root.put("citiesName", shopsDTO.getCitiesName());
            root.put("officeId", shopsDTO.getOfficeId());
            root.put("officeName", shopsDTO.getOfficeName());
            root.put("name", shopsDTO.getName());
            root.put("brand", shopsDTO.getBrand());
            root.put("type", shopsDTO.getType());
            root.put("terminal", shopsDTO.getTerminal());
            root.put("provId", shopsDTO.getProvid());
            root.put("cityId", shopsDTO.getCityid());
            root.put("areaId", shopsDTO.getAreaid());
            root.put("address", shopsDTO.getAddress());
            root.put("shortAddr", shopsDTO.getShortaddr());
            root.put("latitude", shopsDTO.getLatitude());
            root.put("longitude", shopsDTO.getLongitude());
            root.put("busline", shopsDTO.getBusline());
            root.put("subline", shopsDTO.getSubline());
            root.put("particle", shopsDTO.getParticle());
            root.put("status", shopsDTO.getStatus());
            root.put("intro", shopsDTO.getIntro());
            root.put("seatnum", shopsDTO.getSeatnum());
            root.put("daysList",JSON.toJSONString(shopsDTO.getDaysList()));
            root.put("shopsServprodList",toShopsServprodJson(shopsDTO.getShopsServprodList()));
            root.put("area", shopsDTO.getArea());
            root.put("shopTag",JSON.toJSONString(shopsDTO.getShoptag()));
            root.put("kouBeiShopsNum",shopsDTO.getKouBeiShopsNum());
//            root.put("shopsImg", shopsDTO.getShopsImg());
//			String opendate = DateFormat.getDateInstance().format(shopsTable.getOpendate());
            root.put("opendate", shopsDTO.getOpendate());

            //处理时间
            String createdTime =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(shopsDTO.getCreatedTime());
            root.put("createtime", createdTime);
        }

        return root;
    }

    public static ArrayNode toJson(List<ShopsDTO> shopsList) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if(!CommonUtil.isEmpty(shopsList)){
            for (Iterator<ShopsDTO> iterator = shopsList.iterator(); iterator.hasNext();) {
                root.add(toJson(iterator.next()));
            }
        }

        return root;
    }
    //库存颗粒
    public static ObjectNode toGranJson(ShopsGrainApiDTO shopsGrainApiDTOS) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();

        if (shopsGrainApiDTOS != null)
        {
            root.putPOJO("particle", JSON.toJSON(shopsGrainApiDTOS.getParticle()));
            root.putPOJO("seatNum", JSON.toJSON(shopsGrainApiDTOS.getSeatNum()));
            root.putPOJO("grainMax", JSON.toJSON(shopsGrainApiDTOS.getGrainMax()));
            root.putPOJO("daysList", JSON.toJSON(shopsGrainApiDTOS.getDaysList()));
        }
        return root;
    }

    public static ObjectNode toTableJson(ShopsTable shops) {
        ObjectNode root = MAPPER.createObjectNode();

        if (shops != null)
        {
            root.put("id", shops.getId());
            root.put("code", shops.getCode());
            root.put("citiesId", shops.getCitiesId());
            root.put("citiesName", shops.getCitiesName());
            root.put("officeId", shops.getOfficeId());
            root.put("officeName", shops.getOfficeName());
            root.put("name", shops.getName());
            root.put("brand", shops.getBrand());
            root.put("type", shops.getType());
            root.put("terminal", shops.getTerminal());
            root.put("provId", shops.getProvid());
            root.put("cityId", shops.getCityid());
            root.put("areaId", shops.getAreaid());
            root.put("address", shops.getAddress());
            root.put("shortAddr", shops.getShortaddr());
            root.put("latitude", shops.getLatitude());
            root.put("longitude", shops.getLongitude());
            root.put("busline", shops.getBusline());
            root.put("subline", shops.getSubline());
            root.put("particle", shops.getParticle());
            root.put("status", shops.getStatus());
            root.put("intro", shops.getIntro());
            root.put("seatnum", shops.getSeatnum());
            root.put("area", shops.getArea());
            root.put("shopTag", shops.getShoptag());
//			String opendate = DateFormat.getDateInstance().format(shopsTable.getOpendate());
            root.put("opendate", shops.getOpendate());

            //处理时间
            String createdTime = DateFormat.getDateTimeInstance().format(shops.getCreatedTime());//可以精确到时分秒
            root.put("createtime", createdTime);
        }

        return root;
    }

    public static ArrayNode toTableJson(List<ShopsTable> shopsList) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if(!CommonUtil.isEmpty(shopsList)){
            for (Iterator<ShopsTable> iterator = shopsList.iterator(); iterator.hasNext();) {
                root.add(toTableJson(iterator.next()));
            }
        }

        return root;
    }

    public static ObjectNode toJsonPage(Page<ShopsTable> page) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();
        if (page != null)
        {
            root.put("pageNo", page.getPageNo());
            root.put("pageSize", page.getPageSize());
            root.put("pageTotal", page.getPageTotal());
            root.put("recordTotal", page.getRecordTotal());
            root.put("dtoLists", toTableJson(page.getDtoList()));
        }
        return root;
    }
    //处理店铺时间价格返回值

//    public static ArrayNode toShopsServprodJson(List<ShopsServprodTable> shopsServprodList) throws Throwable {
//        ArrayNode root = MAPPER.createArrayNode();
//
//        if(!CommonUtil.isEmpty(shopsServprodList)){
//            for (Iterator<ShopsServprodTable> iterator = shopsServprodList.iterator(); iterator.hasNext();) {
//                root.add(toShopsServprodJson(iterator.next()));
//            }
//        }
//
//        return root;
//    }

    public static ArrayNode toShopsServprodJson(List<ShopsServprodDTO> shopsServprodList) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if(!CommonUtil.isEmpty(shopsServprodList)){
            for (Iterator<ShopsServprodDTO> iterator = shopsServprodList.iterator(); iterator.hasNext();) {
                root.add(toShopsServprodJson(iterator.next()));
            }
        }

        return root;
    }



    public static ObjectNode toShopsServprodJson(ShopsServprodDTO shopsServprod) throws Exception {
        ObjectNode root = MAPPER.createObjectNode();

        if (shopsServprod != null)
        {
            root.put("checked", shopsServprod.getChecked());
            root.put("servprodId",shopsServprod.getServprodId());
            root.put("servprodName", shopsServprod.getServprodName());
            root.put("price", shopsServprod.getPrice());
            root.put("servtime", shopsServprod.getServtime());
            root.put("shopsId", shopsServprod.getShopsId());
        }

        return root;
    }





}
